<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class News extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model('news_model');
	}

	public function index()
	{
        $page = "News";    
	$data['news'] = $this->news_model->get_news();
	$data['title'] = 'News archive';

        
        if ( ! file_exists('application/views/news/index.php'))
            {
		// Whoops, we don't have a page for that!
		show_404();
            }
            $this->load->helper('url');
            $datah['baseurl'] = base_url();
	    $datam['buttons'] = array("Home" => "http://localhost/Learnci", "News" => "index.php/news", "Incidents" => "#", "Alerts" => "#", "Classifieds" => "#", "Admin" => "#"); 
            $datam['mytitle'] = 'Welcome to Area Manager';
            $datam['Administration'] = array("Users", "Areas", "Area Groups", "Security", "Classifieds");
            $datam['Classifieds'] = array("New", "Edit", "Delete", "Approve", "Bill");
            $data['title'] = ucfirst($page); // Capitalize the first letter
	
            $this->load->view('templates/header', $datah);
            $this->load->view('menus/mainmenu', $datam);
            //$this->load->view('pages/home');
            //echo modules::run('localhost/Learnci/menu/pagemenu', "home"); 
            //$this->load->view('menus/'.$page, $data);
            $this->load->view('templates/sidebar');
            $this->load->view('news/index', $data);
            
            $this->load->view('templates/footer', $data);
        
	}

	public function view($slug)
	{
            $data['news_item'] = $this->news_model->get_news($slug);

            if (empty($data['news_item']))
            {
		show_404();
            }

            $data['title'] = $data['news_item']['title'];

            $this->load->view('templates/header', $data);
            $this->load->view('menus/mainmenu');
            $this->load->view('news/view', $data);
            $this->load->view('templates/footer');
	}
        
        public function create()
{
	$this->load->helper('form');
	$this->load->library('form_validation');
	
	$data['title'] = 'Create a news item';
	
	$this->form_validation->set_rules('title', 'Title', 'required');
	$this->form_validation->set_rules('text', 'News', 'required');
	
	if ($this->form_validation->run() === FALSE)
	{
		$this->load->view('templates/header', $data);
                $this->load->view('menus/mainmenu');
		$this->load->view('news/create');
		$this->load->view('templates/footer');
		
	}
	else
	{
		$this->news_model->set_news();
		$this->load->view('news/success');
	}
}
        
        
        
}
?>
